package com.qianbao.qianbaobusiness.ui.cashier;

import com.androidbase.base.mvp.RxMvpPresenter;
import com.androidbase.utils.RxUtils;
import com.baseandroid.config.MyApi;
import com.baseandroid.retrofit.RxObserver;
import com.baseandroid.retrofit.json.Data;
import com.qianbao.qianbaobusiness.json.CashierDetailBean;

import javax.inject.Inject;

public class CashierDetailPresenter extends RxMvpPresenter<CashierDetailView> {

    MyApi mApi;

    @Inject
    public CashierDetailPresenter(MyApi api) {
        mApi = api;
    }

    /**
     * 根据商户号，订单号查询订单详情
     * @param merchantNo
     * @param orderNo
     */
    public void getOrderInfo(String merchantNo, String orderNo) {
        mApi.getOrderInfo(merchantNo,orderNo)
                .compose(RxUtils.applySchedulersLifeCycle(getView()))
                .subscribe(new RxObserver<Data<CashierDetailBean>>(){
                    @Override
                    public void onComplete() {
                        getView().onComplete();
                    }

                    @Override
                    public void onNext(Data<CashierDetailBean> cashierDetailBeanData) {
                        if (RxObserver.checkJsonCode(cashierDetailBeanData, false)) {
                            getView().onNext(cashierDetailBeanData.getResult());
                        }else {
                            getView().onError();
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        getView().onError();
                    }
                });

    }
}
